/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.base.radar;


import com.hitechbangla.fctu.utility.GeneralUtil;
import fctu.simulator.HTB_MAIN;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Arc2D;
import java.io.Serializable;
import java.util.Random;

/**
 *
 * @author Asus
 */
public class SyncBarrageEcm implements EcmDrawable, Serializable {
    
    private int centerXOfArc;
    private int centerYOfArc;
    private int widthOfArc;
    private int heightOfArc;
    private int startAngle;
    private int arcAngle;
    private int aircraftPositionX;
    private int aircraftPositionY;
    private int radarPositionX;
    private int radarPositionY;
    private int radarRange;
    int nextStartAngle;
    int nextArcAngle;
    int nextStartAngle2;
    int nextArcAngle2;
    int nextStartAngle3;
    int nextArcAngle3;
    int sAngle;
    int randomNumber2;
    int randomNumber3;
    int a[][][] ;
    int b[][][];
    int e[][][];
    int d[][][];
    int intervals;
    int randomNumForSec1,randomNumForSec2,randomNumForSec3;
    int shiftOFArc1,shiftOFArc2, shiftOFArc3;
    int leftRectX,leftRectY;
    int arcWidth, arcHeight;
    int toggle;
    public SyncBarrageEcm(int centerXOfArc, int centerYOfArc, int widthOfArc,
			int heightOfArc, int startAngle, int arcAngle,
			int airPosX, int airPosY) {
	this.centerXOfArc = centerXOfArc;
	this.centerYOfArc = centerYOfArc;
	this.widthOfArc = widthOfArc;
	this.heightOfArc = heightOfArc;
	this.startAngle = startAngle;
	this.arcAngle = arcAngle;
	aircraftPositionX = airPosX;
	aircraftPositionY = airPosY;
	radarRange = (int)(widthOfArc/2);
	radarPositionX = centerXOfArc + radarRange;
	radarPositionY = centerYOfArc + radarRange;
	
	sAngle = (int)(-startAngle);
	
	leftRectX = radarPositionX-radarRange;
	leftRectY = radarPositionX-radarRange;
	arcWidth = 2*radarRange;
	arcHeight = 2*radarRange;
	Random random = new Random();		
	randomNumForSec1 = GeneralUtil.getRandomIntegerInRange(30, 50, random);
	randomNumForSec2 = GeneralUtil.getRandomIntegerInRange(25, 50, random);
	randomNumForSec3 = GeneralUtil.getRandomIntegerInRange(25, 50, random);
	
	shiftOFArc1 = 10;
	shiftOFArc2 = 80;
	shiftOFArc3 = 120;
	
	toggle = 0;
    }
    
    @Override
    public void draw(Graphics g, EpmType epmType) {
	
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setPaint(Color.BLACK);
	
	BasicStroke wideStroke = new BasicStroke(27.0f);
	g2.setStroke(wideStroke);
	//throw new UnsupportedOperationException("Not supported yet.");
	GeneralUtil.log("by ratan " + sAngle+" "+startAngle +" "+ centerXOfArc + " " + centerYOfArc + " " + widthOfArc + " " + heightOfArc + " " + startAngle + " " + arcAngle);
	Color c = g.getColor();
	g.setColor(Color.black);
	
	int x1 = leftRectX + shiftOFArc1;
	int y1 = leftRectY + shiftOFArc1;
	int x2 = leftRectX + shiftOFArc2;
	int y2 = leftRectY + shiftOFArc2;
	int x3 = leftRectX + shiftOFArc3;
	int y3 = leftRectY + shiftOFArc3;
	
	double distanceBetweenRadAndArcft = GeneralUtil.distance2D(aircraftPositionX, aircraftPositionY
					    , radarPositionX, radarPositionY);
	int distance = (int) distanceBetweenRadAndArcft;
	if(distance>= radarRange)
	{
	    GeneralUtil.log("Aircraft Out Of range!!"+distance+ " : " +radarRange);
	}else{
	    System.out.println("which quadrant : "+startAngle);
	    if( (startAngle> 0) && (startAngle <90) )
	    {
		System.out.println("1st qndrnt");
		    System.out.println("Radar range :"+radarRange);
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1, radarPositionY - radarRange + shiftOFArc1,
			    2 * radarRange - 2 * (shiftOFArc1), 2 * radarRange - 2 * (shiftOFArc1), 270, 90-8, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+54, radarPositionY - radarRange + shiftOFArc1+54,
			    2 * radarRange - 2 * (shiftOFArc1+54), 2 * radarRange - 2 * (shiftOFArc1+54), 270, 90-8, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+108, radarPositionY - radarRange + shiftOFArc1+108,
			    2 * radarRange - 2 * (shiftOFArc1+108), 2 * radarRange - 2 * (shiftOFArc1+108), 270, 90-8, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+163, radarPositionY - radarRange + shiftOFArc1+163,
			    2 * radarRange - 2 * (shiftOFArc1+162), 2 * radarRange - 2 * (shiftOFArc1+162), 270+3, 90-8, Arc2D.OPEN));
	    }
	    if (startAngle > 90 && startAngle < 180) {
		System.out.println("q2");
		System.out.println("Radar range :"+radarRange);
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1, radarPositionY - radarRange + shiftOFArc1,
			    2 * radarRange - 2 * (shiftOFArc1), 2 * radarRange - 2 * (shiftOFArc1), 360, 90-8, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+54, radarPositionY - radarRange + shiftOFArc1+54,
			    2 * radarRange - 2 * (shiftOFArc1+54), 2 * radarRange - 2 * (shiftOFArc1+54), 360, 90-8, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+108, radarPositionY - radarRange + shiftOFArc1+108,
			    2 * radarRange - 2 * (shiftOFArc1+108), 2 * radarRange - 2 * (shiftOFArc1+108), 360, 90-8, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+162, radarPositionY - radarRange + shiftOFArc1+162,
			    2 * radarRange - 2 * (shiftOFArc1+162), 2 * radarRange - 2 * (shiftOFArc1+162), 360, 90-8, Arc2D.OPEN));
	    }
	    if (startAngle > 180 && startAngle < 270) {
		System.out.println("q3");
		System.out.println("Radar range :"+radarRange);
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1, radarPositionY - radarRange + shiftOFArc1,
			    2 * radarRange - 2 * (shiftOFArc1), 2 * radarRange - 2 * (shiftOFArc1), 90, 90, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+54, radarPositionY - radarRange + shiftOFArc1+54,
			    2 * radarRange - 2 * (shiftOFArc1+54), 2 * radarRange - 2 * (shiftOFArc1+54), 90, 90, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+108, radarPositionY - radarRange + shiftOFArc1+108,
			    2 * radarRange - 2 * (shiftOFArc1+108), 2 * radarRange - 2 * (shiftOFArc1+108), 90, 90, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+162, radarPositionY - radarRange + shiftOFArc1+162,
			    2 * radarRange - 2 * (shiftOFArc1+162), 2 * radarRange - 2 * (shiftOFArc1+162), 90, 90, Arc2D.OPEN));
	    }
	    if (startAngle > 270 && startAngle < 359) {
		System.out.println("q4");
		System.out.println("Radar range :"+radarRange);
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1, radarPositionY - radarRange + shiftOFArc1,
			    2 * radarRange - 2 * (shiftOFArc1), 2 * radarRange - 2 * (shiftOFArc1), 180, 90, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+54, radarPositionY - radarRange + shiftOFArc1+54,
			    2 * radarRange - 2 * (shiftOFArc1+54), 2 * radarRange - 2 * (shiftOFArc1+54), 180, 90, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+108, radarPositionY - radarRange + shiftOFArc1+108,
			    2 * radarRange - 2 * (shiftOFArc1+108), 2 * radarRange - 2 * (shiftOFArc1+108), 180, 90, Arc2D.OPEN));
		    g2.draw(new Arc2D.Double(radarPositionX - radarRange + shiftOFArc1+162, radarPositionY - radarRange + shiftOFArc1+162,
			    2 * radarRange - 2 * (shiftOFArc1+162), 2 * radarRange - 2 * (shiftOFArc1+162), 180, 90, Arc2D.OPEN));
	    }
	}
	
	g.setColor(c);
	
    }	
    
    
}
